package leetcode.d1;


public class R3531 {
    public int countCoveredBuildings(int n, int[][] buildings) {
        int row = buildings.length;
        int col = buildings[0].length;
        int[] left = new int[n + 1];
        int[] right = new int[n + 1];
        int[] up = new int[n + 1];
        int[] dowm = new int[n + 1];
        int res = 0;
        for (int[] building : buildings) {
            int x = building[0];
            int y = building[1];
            left[y] = Math.min(left[y] == 0 ? Integer.MAX_VALUE : left[y], x);
            right[y] = Math.max(right[y], x);
            up[x] = Math.max(up[x], y);
            dowm[x] = Math.min(dowm[x] == 0 ? Integer.MAX_VALUE : dowm[x], y);
        }
        for (int[] building : buildings) {
            int x = building[0];
            int y = building[1];
            if (left[y] < x && x < right[y] && dowm[x] < y && y < up[x]) {
                res++;
            }
        }
        return res;
    }


}
